(* wiem że są biblioteki ale dla jaj robie swoje *)
let single_byte_char c = ((int_of_char c) land 0x80) = 0x00
let non_head_char c = ((int_of_char c) land 0xC0) == 0x80
let two_bytes_char c = ((int_of_char c) land 0xE0) == 0xC0
let three_bytes_char c = ((int_of_char c) land 0xF0) == 0xE0
let four_bytes_char c = ((int_of_char c) land 0xF8) == 0xF0

let char_length c =
  if single_byte_char c then 1 else
  if two_bytes_char c then 2 else
  if three_bytes_char c then 3 else
    4
